// pages/activedetial/activedetial.js
var WxParse = require("../../wxParse/wxParse.js");
var api = require("../../api.js"),
  app = getApp();
var r;
Page({
  /**
   * 页面的初始数据
   */
  data: {
    name: '',
    detail_desc: '',
    industry: '',
    address: '',
    phone: '',
    contactsName: '',
    contactsPhone: '',
    certificatesImg: '../../images/upload.png',
    headPortrait: '../../images/upload.png',
    img: '../../images/upload.png'
  },
  chooseLogo: function(e) {
    var _that = this;
    let type = e.currentTarget.dataset.imgtype;
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        console.log(res)
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths
        wx.uploadFile({
          url: 'http://192.168.3.66/common/wxUploadPic', //仅为示例，非真实的接口地址
          filePath: tempFilePaths[0],
          name: 'file',
          formData: {},
          success(resp) {
            const data = JSON.parse(resp.data).data
            _that.setData({
              [type]: data.url
            })
          }
        })
      }
    })
  },
  submit: function () {
    let sendData = {
      openId: app.globalData.wxUserInfo.openId,
      name: this.data.name,
      detailDesc: this.data.detail_desc,
      industry: this.data.industry,
      address: this.data.address,
      phone: this.data.phone,
      contactsName: this.data.contactsName,
      contactsPhone: this.data.contactsPhone,
      certificatesImg: this.data.certificatesImg,
      headPortrait: this.data.headPortrait,
      img: this.data.img
    }
    wx.request({
      url: api.company.creatCompany,
      data: sendData,
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      method: 'POST',
      success(res) {
        if(res.data.code === 200) {
          wx.navigateBack()
        } else {
          wx.showToast({
            title: '申请失败，请稍后再试',
            icon: 'none',
            duration: 2000
          })
        }
      }
    });
  },
  bindKeyInput: function (e){
    console.log(e);
    let item = e.currentTarget.dataset.model;
    this.setData({
      [item]: e.detail.value
    });
  },
  /**
   * 生命周期函数--监听页面加载
   *
   */
  onLoad: function (options) {
    r = this;
    //  console.log(options)
    var id = options.id;
    this.setData({
      id: id,
      sys: app.globalData.systeminfo
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  
  onReady: function () { },
  /**
   * 生命周期函数--监听页面显示
   */
  // onShow: function () {
  //   var _this = this;
  //   r.toast = _this.selectComponent("#toast");
  //   var userid = getApp().globalData.wxUserInfo.openId;
  //   wx.showLoading({
  //     title: "数据加载中"
  //   });
  //   var t = new Object();
  //   t.artId = _this.data.id
  //   t.openId = userid
  //   app.getData.artDetail(t).then(res => {
  //     wx.hideLoading();
  //     // setTimeout(function () {
  //     //   wx.hideLoading();
  //     //   // const img = res.data.artDesc;
  //     //   res.data.artDesc = img.replace(/\<img/gi, '<img style="max-width:100%;height:auto;" ')
  //     //   _this.setData({
  //     //     artDetail: res.data,
  //     //     isCollection: res.data.isCollection,
  //     //     userid: userid
  //     //   });
  //     //   // WxParse.wxParse("artDesc","html", res.data.artDesc,_this,5);
  //     // }, 500);

  //   }).catch(res => {
  //     wx.hideLoading();
  //     _this.setData({
  //       artDetail: [],
  //     });
  //   })
  // },
});
